package com.project.authentication.service.impl;

import com.baomidou.dynamic.datasource.annotation.DS;
import com.project.authentication.entity.UserLog;
import com.project.authentication.mapper.UserLogMapper;
import com.project.authentication.service.UserLogService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import tk.mybatis.mapper.entity.Example;

import javax.annotation.Resource;
import java.util.List;

@Service
public class UserLogServiceImpl implements UserLogService {

    @Resource
    private UserLogMapper userLogMapper;

    @Override
    @DS("master")
    public List<UserLog> getByToken(String token) {
        Example example = new Example(UserLog.class);
        Example.Criteria c = example.createCriteria();
        c.andEqualTo("sessionid", token);
        return userLogMapper.selectByExample(example);
    }

    @Transactional(rollbackFor = Exception.class)
    @Override
    @DS("master")
    public void insert(UserLog entity) {
        userLogMapper.insertSelective(entity);
    }
}
